<template>
  <view class="work-container">
	<!-- 下拉框-->
	<uni-forms class="queryForm" ref="queryForm" :modelValue="queryParams">
		<uni-forms-item>
			<uni-data-select class="queryFormSelect" v-model="queryParams.phouseType" placeholder="请选择猪舍类型"
				:localdata="hmy_park_type" @change="handleQuery"></uni-data-select>
		</uni-forms-item>
	</uni-forms>

	<uni-group mode="card" v-for="(item, index) in phouseList" :index="index" :key="index">
		<view class="code">
			<text style="font-size:18px">猪舍编码：{{item.phouseCode}}</text>
			<uni-icons class="iconRight" type="right" size="15" color="#000000" @click="toDetials(item.phouseId)"></uni-icons>
		</view>
		<hr/>
		<view class="message">
			<view v-if="item.phouseType == 1"> 猪舍类型：{{$dict.selectDictLabel('hmy_park_type', 1)}} </view>
			<view v-else-if="item.phouseType ==2"> 猪舍类型：{{$dict.selectDictLabel('hmy_park_type', 2)}}
			</view>
			<view v-else-if="item.phouseType ==3"> 猪舍类型：{{$dict.selectDictLabel('hmy_park_type', 3)}}
			</view>
			<view v-else-if="item.phouseType ==4"> 猪舍类型：{{$dict.selectDictLabel('hmy_park_type', 4)}}
			</view>
			<view v-else-if="item.phouseType ==5"> 猪舍类型：{{$dict.selectDictLabel('hmy_park_type', 5)}}
			</view>
			<view v-else-if="item.phouseType ==6"> 猪舍类型：{{$dict.selectDictLabel('hmy_park_type', 6)}}
			</view>
			<view> 负责人：{{item.hmyStaff.staffName}}</view>
			<!-- <view v-if="item.staffName == 1">
				负责人：{{$dict.selectDictLabel('staffNames', 1)}} </view>
			<view v-else-if="item.staffName ==2">
				负责人：{{$dict.selectDictLabel('staffNames', 2)}} </view>
			<view v-else-if="item.staffName ==3">
				负责人：{{$dict.selectDictLabel('staffNames', 3)}} </view>
			<view v-else-if="item.staffName ==4">
				负责人：{{$dict.selectDictLabel('staffNames', 4)}} </view> -->
		</view>
	</uni-group>
	<!-- 加载更多 -->
	<uni-load-more iconType="auto" :status="status" />
	<!-- 新增加号 -->
	<uni-fab :pattern="pattern" :horizontal="horizontal" :vertical="vertical" @fabClick="toPhouseAdd" />
  </view>
</template>

<script>
import {addPhouse, delPhousr, findCode, getPhouse, listPhouse, updatePhousr} from "@/api/hmy/phouse";
import {listStaff} from "@/api/hmy/staff";

export default {
  name: "Phouse",
  dicts: ['sys_normal_disable', 'hmy_park_type', 'hmy_presence_absence'],
  data() {
    return {
	    hmy_park_type: [{
				value: 1,
				text: '公猪舍'
			},
			{
				value: 2,
				text: '母猪舍'
			},
			{
				value: 3,
				text: '肉猪舍'
			}
		],
      // 遮罩层
      loading: true,
      // 角色表格数据
      phouseList: [],
      //获取员工列表
      hmyStaffList: [],
      //增加的加号
	horizontal: 'right',
	vertical: 'bottom',
	pattern: {
		buttonColor: '#55aa7f',
	},
	//加载更多
	status: 'more',
	total: '',
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        phouseCode: undefined,
        phouseType: undefined,
        staffName: undefined,
        beganTime: undefined,
        endTime: undefined,
        phouseManager: 0
      },
	  created() {
		this.getList();
	  },
	  //上拉加载
	onReachBottom() {
		this.queryParams.pageSize += 5;
		this.getList();
		if (this.phouseList.length >= this.total) {
			this.status = 'noMore';
			//console.log(this.status);
		} else {
			this.status = 'loading';
		}
	},
      // 表单校验
      rules: {
        phouseCode: [
          {required: true, message: "猪舍编码不能为空", trigger: "blur"},
          {validator: this.checkCode, trigger: 'blur'}
        ],
        phouseManager: [
          {required: true, message: "负责人不能为空", trigger: "blur"}
        ],
        phouseType: [
          {required: true, message: "猪舍类型不能为空", trigger: "blur"}
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询角色列表 */
    getList() {
      uni.showLoading({
      	title:"加载中"
      })
      listPhouse(this.queryParams).then(response => {
          this.phouseList = response.rows;
          this.total = response.total;
		  uni.hideLoading();
        }
      );
    },
	//新增进货加号
	toPhouseAdd() {
		this.$tab.navigateTo('/pages/hmy/phouse/phouseAdd');
	},
    
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    
    //详情
	toDetials(e) {
		this.$tab.navigateTo('/pages/hmy/phouse/phouseDetails?id=' + e);
	}
  }
};
</script>

<style lang="scss">
	/* #ifndef APP-NVUE */
	page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		min-height: 100%;
		height: auto;
		background-color: #fcfcfc;
	}

	view {
		font-size: 16px;
		line-height: inherit;
	}

	/* #endif */
	.code {
		margin-bottom: 5px;
	}
	
	.iconleft {
		float: left;
		// margin-right: 10px;
		// margin-top: 5px;
	}

	.iconRight {
		float: right;
		margin-right: 10px;
		margin-top: 5px;
	}

	.message {
		margin-top: 5px;
		color: #838383;
		line-height: 25px;
	}

	.queryForm {
		background-color: #fff;
		width: 350px;
		margin-top: 8px;
		margin-left: 10px;
	}
</style>